#pragma once
//将魔术公式抽离出来.并尽量将共用的中间变量从函数中抽离出来

class MagicFormula{
private:
    //    double parameters[50];		//方程系数列表
    //	double parametersPre[50];	//内部调用方程的系数列表

    inline double sign(double num){		//matlab里的符号函数
        if (num){
            return (num>0) ? 1 : -1;;
        }
        else{
            return 0;
        };
    }
    //一些公共的中间变量，其中0-1对应如下变量：Fzo、dfz
    double dataPrivate[2];				// 0    1
    //PrivateFx函数的中间变量，其中0-10对应如下变量：Shx、Svx、kx、Cx、Dx、Ex、CFx、Bx、Fxo
    double dataPrivateFx[9];			//		 0    1   2   3   4   5   6   7   8
    //PrivateFx函数的中间变量，其中0-10对应如下变量：Shy、Svy、alpha_y、Cy、uy、Dy、Ey、CFy、By、Fyo
    double dataPrivateFy[10];			//		  0   1     2      3   4   5  6   7    8   9
    //PrivateFx函数的中间变量，其中0-11对应如下变量：Ro、alpha_t、Bt、Ct、Dt、Et、t、alpha_r、Br、Cr、Dr、Mzr、
    double dataPrivateMz[12];			//	     0     1     2    3  4   5  6    7      8   9  10  11
    //PrivateCombFx函数的中间变量，其中0-5对应如下变量：alpha_s、Bxa、Exa、Gxa、Gxa2、CombFxsim0
    double dataPrivateCombFx[6];		//			  0      1    2    3    4     5
    //PrivateCombFy函数的中间变量，其中0-7对应如下变量：Shyk、k_s、Byk、Eyk、Svyk、Gyk1、Gyk2、CombFysim0
    double dataPrivateCombFy[8];		//           0    1    2    3    4    5     6     7
    //PrivateCombMz函数的中间变量，其中0-4对应如下变量：alpha_teq、tMz、alpha_req、MzrMz、s
    double  dataPrivateCombMz[5];       //            0        1      2         3   4

protected:
    //六个魔术公式的最优参数结果
    double parametersPrivateFx[15];
    double parametersPrivateFy[18];
    double parametersPrivateMz[25];
    double parametersPrivateCombFx[6];
    double parametersPrivateCombFy[14];
    double parametersPrivateCombMz[4];

public:
    MagicFormula();
    ~MagicFormula();

    void inline inputFzoRo(double FzoIn,double RoIn){
        dataPrivate[0] = FzoIn;
        dataPrivateMz[0] = RoIn;
    }	//设置Fzo的值，这个值只与轮胎本身属性有关

    //---------------------方程及系数的偏导函数--------------------------
    double PrivateFx(double Fz, double k, double r, double parameters[]);		//纯纵滑纵向力
    double PrivateFy(double Fz, double alpha, double r, double parameters[]);	//纯纵滑纵向力
    double PrivateMz(double Fz, double alpha, double r, double parameters[]);	//纯侧偏回正力矩
    double PrivateCombFx(double Fz, double k, double alpha, double r, double parameters[]);//联合工况纵向力
    double PrivateCombFy(double Fz, double k, double alpha, double r, double parameters[]);//联合工况侧向力
    double PrivateCombMz(double Fz, double k, double alpha, double r, double parameters[]);//联合工况回正力矩

    //六个魔术方程的系数初始化函数
    void InitialPrivateFx(double parameters[]);
    void InitialPrivateFy(double parameters[]);
    void InitialPrivateMz(double parameters[]);
    void InitialPrivateCombFx(double parameters[]);
    void InitialPrivateCombFy(double parameters[]);
    void InitialPrivateCombMz(double parameters[]);

    //方程PrivateFx相对各个系数的偏导函数，15个系数
    double PrivateFx_00(double Fz, double k, double r, double parameters[]);
    double PrivateFx_01(double Fz, double k, double r, double parameters[]);
    double PrivateFx_02(double Fz, double k, double r, double parameters[]);
    double PrivateFx_03(double Fz, double k, double r, double parameters[]);
    double PrivateFx_04(double Fz, double k, double r, double parameters[]);
    double PrivateFx_05(double Fz, double k, double r, double parameters[]);
    double PrivateFx_06(double Fz, double k, double r, double parameters[]);
    double PrivateFx_07(double Fz, double k, double r, double parameters[]);
    double PrivateFx_08(double Fz, double k, double r, double parameters[]);
    double PrivateFx_09(double Fz, double k, double r, double parameters[]);
    double PrivateFx_10(double Fz, double k, double r, double parameters[]);
    double PrivateFx_11(double Fz, double k, double r, double parameters[]);
    double PrivateFx_12(double Fz, double k, double r, double parameters[]);
    double PrivateFx_13(double Fz, double k, double r, double parameters[]);
    double PrivateFx_14(double Fz, double k, double r, double parameters[]);
    //方程PrivateFy相对各个系数的偏导函数，18个系数
    double PrivateFy_00(double parameters[]);
    double PrivateFy_01(double Fz, double r, double parameters[]);
    double PrivateFy_02(double Fz, double r, double parameters[]);
    double PrivateFy_03(double Fz, double r, double parameters[]);
    double PrivateFy_04(double r, double parameters[]);
    double PrivateFy_05(double r, double parameters[]);
    double PrivateFy_06(double parameters[]);
    double PrivateFy_07(double r, double parameters[]);
    double PrivateFy_08(double Fz, double r, double parameters[]);
    double PrivateFy_09(double Fz, double r, double parameters[]);
    double PrivateFy_10(double Fz, double r, double parameters[]);
    double PrivateFy_11(double parameters[]);
    double PrivateFy_12(double parameters[]);
    double PrivateFy_13(double r, double parameters[]);
    double PrivateFy_14(double Fz);
    double PrivateFy_15(double Fz);
    double PrivateFy_16(double Fz, double r);
    double PrivateFy_17(double Fz, double r);
    //方程PrivateMz相对各个系数的偏导函数，25个系数
    double PrivateMz_00(double alpha, double r, double parameters[]);
    double PrivateMz_01(double alpha, double r, double parameters[]);
    double PrivateMz_02(double alpha, double r, double parameters[]);
    double PrivateMz_03(double alpha, double r, double parameters[]);
    double PrivateMz_04(double alpha, double r, double parameters[]);
    double PrivateMz_05(double alpha);
    double PrivateMz_06(double alpha);
    double PrivateMz_07(double alpha, double r, double parameters[]);
    double PrivateMz_08(double Fz, double alpha, double r, double parameters[]);
    double PrivateMz_09(double Fz, double alpha, double r, double parameters[]);
    double PrivateMz_10(double Fz, double alpha, double r, double parameters[]);
    double PrivateMz_11(double Fz, double alpha, double r, double parameters[]);
    double PrivateMz_12(double Fz, double alpha);
    double PrivateMz_13(double Fz, double alpha);
    double PrivateMz_14(double Fz, double alpha, double r);
    double PrivateMz_15(double Fz, double alpha, double r);
    double PrivateMz_16(double alpha, double r, double parameters[]);
    double PrivateMz_17(double alpha, double r, double parameters[]);
    double PrivateMz_18(double alpha, double r, double parameters[]);
    double PrivateMz_19(double alpha, double parameters[]);
    double PrivateMz_20(double alpha, double r, double parameters[]);
    double PrivateMz_21(double alpha, double parameters[]);
    double PrivateMz_22(double alpha, double parameters[]);
    double PrivateMz_23(double alpha, double r, double parameters[]);
    double PrivateMz_24(double alpha, double r, double parameters[]);
    //方程PrivateCombFx相对各个系数的偏导函数，6个系数
    double PrivateCombFx_00(double k, double parameters[]);
    double PrivateCombFx_01(double k, double parameters[]);
    double PrivateCombFx_02(double parameters[]);
    double PrivateCombFx_03(double parameters[]);
    double PrivateCombFx_04(double parameters[]);
    double PrivateCombFx_05(double parameters[]);
    //方程PrivateCombFy相对各个系数的偏导函数，14个系数
    double PrivateCombFy_00(double alpha, double parameters[]);
    double PrivateCombFy_01(double alpha, double parameters[]);
    double PrivateCombFy_02(double alpha, double parameters[]);
    double PrivateCombFy_03(double parameters[]);
    double PrivateCombFy_04(double parameters[]);
    double PrivateCombFy_05(double parameters[]);
    double PrivateCombFy_06(double parameters[]);
    double PrivateCombFy_07(double parameters[]);
    double PrivateCombFy_08(double Fz, double k, double alpha, double parameters[]);
    double PrivateCombFy_09(double Fz, double k, double alpha, double parameters[]);
    double PrivateCombFy_10(double Fz, double k, double alpha, double r, double parameters[]);
    double PrivateCombFy_11(double Fz, double k, double alpha, double r, double parameters[]);
    double PrivateCombFy_12(double Fz, double k, double alpha, double r, double parameters[]);
    double PrivateCombFy_13(double Fz, double k, double alpha, double r, double parameters[]);
    //方程PrivateCombMz相对各个系数的偏导函数，4个系数
    double PrivateCombMz_00();
    double PrivateCombMz_01();
    double PrivateCombMz_02(double r);
    double PrivateCombMz_03(double r);
    //----------------------------------------------------------------
};
